import {List,Toast} from 'antd-mobile';
const Item = List.Item;
const Brief = Item.Brief;
import SVGIcon from "../../modules/svgIcon.jsx";

class ShopInfo extends React.Component{

    imgClick(phone,callType){
        if(phone) {
            if (callType && callType == 0)
                window.location.href = "native:appCall:" + phone;
            else
                window.location.href = "tel:" + phone;
        }
        else
            Toast.info("商户手机号码未录入!",1);
    }

    getCustomContent(content,key){
        for(let i=0;i<content.length;i++){
            if(content[i].customKey == key)
                return content[i].customValue;
        }
        return null;
    }

    itemOnClick(resource){
        if(resource.content_url) {
            this.props.history.push("/shops/detail",{url:resource.content_url})
        }else{
            Toast.info("该店铺暂无详情");
        }
    }

    render(){
        return(
            <div>
            {
                this.props.location.state.map((resource)=>{
                    let phone = this.getCustomContent(resource.customContent,'phone');
                    let address = this.getCustomContent(resource.customContent,'address');
                    let callType = this.getCustomContent(resource.customContent,'callType');
                    return (
                        <List>
                            <Item
                                thumb={resource.icon_url?resource.icon_url:<SVGIcon type="shangdian" size="lg"/>}
                                extra={<SVGIcon type="dial" size="lg" onClick={()=>this.imgClick(phone,callType)}/>}
                            >
                                <div onClick={()=>this.itemOnClick(resource)}>
                                    {resource.title}
                                    <Brief><SVGIcon type="coordinates" size="sm"/>{address}</Brief>
                                </div>
                            </Item>
                        </List>
                    )
                })
            }
            </div>
        )
    }
}

export default ShopInfo;